class Solution:
    def dfs(self,board,i,j):
        print(i,j)
        if i < 0 or j < 0 or i >= self.max_line or j >= self.max_row:
            return
        if board[i][j]!='O' :
            return
        board[i][j] = '$'
        self.dfs(board,i+1,j)
        self.dfs(board,i-1,j)
        self.dfs(board,i,j+1)
        self.dfs(board,i,j-1)
    
    def solve(self, board):
        """
        :type board: List[List[str]]
        :rtype: void Do not return anything, modify board in-place instead.
        """
        if len(board) == 0:
            return []
        self.max_line = len(board)
        self.max_row = len(board[0])
        for j in range(self.max_row):
            if board[0][j] == "O":
                self.dfs(board,0,j)
            if board[-1][j] == "O":
                self.dfs(board,self.max_line-1,j)
        for i in range(self.max_line):
            if board[i][0] == "O":
                self.dfs(board,i,0)
            if board[i][-1] == "O":
                self.dfs(board,i,self.max_row-1)
                
        for i in range(self.max_line):
            for j in range(self.max_row):
                if board[i][j] == "O":
                    board[i][j] = 'X'
                elif board[i][j] == "$":
                    board[i][j] = "O"
                    
        return board
        
def main():
    sol = Solution()
    print(sol.solve([["O","O"],["O","O"]]))
    
if __name__=="__main__":
    main()